package com.dongdongshop.service.impl;

import com.dongdongshop.data.Page;
import com.dongdongshop.log.DongKeLog;
import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.service.BrankService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@DubboService
public class BrankServiceImpl implements BrankService {

    @Autowired
    private TbBrandMapper tbBrandMapper;


    @Override
    public Page<TbBrand> findList(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<TbBrand> tbBrands = tbBrandMapper.selectByExample(null);
        PageInfo<TbBrand> pageInfo = new PageInfo(tbBrands);
        Page<TbBrand> page = new Page(pageInfo.getPageNum(),pageInfo.getPageSize(),pageInfo.getPages(),pageInfo.getList());
        return page;
    }

//    由于我们查询返回的是集合，分页返回的是page，回显返回的是实体类，删除提交返回的可能是true或者false
//    返回值太乱，不利于前端开发进行判断，因此我们需要将返回统一
    @Override
    @DongKeLog
    public TbBrand selectById(Long id) {
        return tbBrandMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer UpdateInfo(TbBrand tbBrand) {
        return tbBrandMapper.updateByPrimaryKeySelective(tbBrand);
    }

    @Override
    public Integer addInfo(TbBrand tbBrand) {
        return tbBrandMapper.insertSelective(tbBrand);
    }

    @Override
    public Integer deleteInfo(Integer[] ids) {
        return tbBrandMapper.deleteById(ids);
    }

    @Override
    public List<TbBrand> toShow() {
        return tbBrandMapper.selectByExample(null);
    }
}
